package com.unnamed.b.atv.sample.holder;

import com.unnamed.b.atv.model.TreeNode;
import com.unnamed.b.atv.sample.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

import java.security.SecureRandom;

/**
 * SocialViewHolder
 *
 * @author Administrator
 * @Date 2021/5/26
 */
public class SocialViewHolder extends TreeNode.BaseNodeViewHolder<SocialViewHolder.SocialItem> {
    private static final String[] NAMES = new String[]{"Bruce Wayne", "Clark Kent", "Barry Allen", "Hal Jordan"};
    private SecureRandom rand;

    public SocialViewHolder(Context context) {
        super(context);
        rand = new SecureRandom();
    }

    @Override
    public Component createNodeView(TreeNode node, SocialItem value) {
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_social_node, null, false);
        Image iconView = (Image) component.findComponentById(ResourceTable.Id_icon);
        iconView.setPixelMap(value.icon);
        Text connectionsLabel = (Text) component.findComponentById(ResourceTable.Id_connections);
        connectionsLabel.setText(rand.nextInt(150) + " connections");
        Text userNameLabel = (Text) component.findComponentById(ResourceTable.Id_username);
        userNameLabel.setText(NAMES[rand.nextInt(4)]);
        Text sizeText = (Text) component.findComponentById(ResourceTable.Id_size);
        sizeText.setText(rand.nextInt(10) + " items");
        return component;
    }

    @Override
    public void toggle(boolean active) {
    }


    public static class SocialItem {
        private int icon;

        public SocialItem(int icon) {
            this.icon = icon;
        }
    }

}
